package xcu.lxj.nettychat.common.domain.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;




/**
 * @Author XinJian Lei
 * @Date 2024/9/29 11:53
 * @Version 1.0
 */
//响应码枚举类
@Getter
public enum ResCode {

    SUCCESS(200, "成功!"),

    BODY_NOT_MATCH(400, "请求的数据格式不符!"),

    SIGNATURE_NOT_MATCH(401, "请求的数字签名不匹配!"),

    NOT_FOUND(404, "未找到该资源!"),

    INTERNAL_SERVER_ERROR(500, "服务器内部错误!"),

    SERVER_BUSY(503, "服务器正忙，请稍后再试!");

    /**
     * 错误码
     */
    private final Integer code;

    /**
     * 错误描述
     */
    private final String message;
    private static Map<Integer, ResCode> cache;
    static {
        cache = Arrays.stream(ResCode.values()).collect(Collectors.toMap(ResCode::getCode, Function.identity()));
    }

    public static ResCode of(Integer code) {
        return cache.get(code);
    }

    ResCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
}
